#include "DAL\DAL.h"
#include "DAL\DALUtils.h"
#include "DAL\DALCache.h"
#include "DAL\DALFileAccess.h"
#include "UI\UIL.h"
#include "C-Project\DALEntityTranslator.h"
#include "C-Project\BLL.h"

void testDalTranslator()
{
	Supply testSupply;

	testSupply.ID = 42;
	testSupply.Amount = 17;
	testSupply.ProductID = 111;

	DataEntity DE = SupplyToDalEntity(testSupply);

	Supply testSupply2 = DalEntityToSupply(DE);
}

void testDalCache()
{
	//Mock data environment
	char* entities[] = { "foo", "bar" };

	EntityTable mockEntityTable = CreateEntityTable(entities, 2);

	EnvironmentEntityTable = mockEntityTable;

	//Utils memory (required for the cache system)
	AllocateMemories();

	//Test cache

	CreateEntityCaches();

	char mockData[] = { 1, 2, 3, 4 };
	DataEntity mockDEntity;
	mockDEntity.Bytes = 4;
	mockDEntity.Data = mockData;

	SetEntityInCache(0, 1, mockDEntity);
	DeleteEntityInCache(0, 1);
	CreateOrEditEntityInCache(0, 1, mockDEntity);

	CacheEntity CE = GetEntityInCache(0, 1);

	DestructDataEntity(&CE.DataEntity);

	CreateOrEditEntityInCache(0, 1, mockDEntity);
	CreateOrEditEntityInCache(0, 2, mockDEntity);
	CreateOrEditEntityInCache(1, 3, mockDEntity);
	CreateOrEditEntityInCache(1, 4, mockDEntity);

	//De-allocation and de-mock

	DestructEntityCaches();

	FreeMemories();

	DestructEntityTable(EnvironmentEntityTable);
}

void testDalFileAccess()
{
	//Mock data environment
	char* entities[] = { "foo", "bar" };

	EntityTable mockEntityTable = CreateEntityTable(entities, 2);

	EnvironmentEntityTable = mockEntityTable;
	EnvironmentDirectoryPath = "D:\\Test\\";

	//Utils memory (required for the cache system)
	AllocateMemories();

	//Test cache

	EstablishFileSystem();

	char mockData[] = { 'a', 'b', 'c', 'd' };
	DataEntity mockDEntity;
	mockDEntity.Bytes = 4;
	mockDEntity.Data = mockData;

	DataEntity getEntity = GetEntityInFile(0, 20);

	DestructDataEntity(&getEntity);
	
	//De-allocation and de-mock

	FreeFileSystem();

	FreeMemories();

	DestructEntityTable(EnvironmentEntityTable);
}

void testUi()
{
	User UserObj;
	UserObj.UserName = "j";
	UserObj.UserPrivlage = Manager;

}

int main()
{

	//testDalCache();
	//testDalFileAccess();
	//testUi();
	//testDalTranslator();
	return 0;
}